<?php
if(!$_SESSION["user"]){
    // 未登录, 跳转登录页面
    header("location:/shop/login.html");
    return;
}

require_once("productDao.php");
$id = $_REQUEST["id"];

$result = selectById($id);
$p = $result['data'];
if($p){
    // 显示商品信息
    echo "<!DOCTYPE html>";
    echo "<html lang='zh'>";
    echo "<head>";
    echo "    <meta charset='UTF-8'>";
    echo "    <meta http-equiv='X-UA-Compatible' content='IE=edge'>";
    echo "    <meta name='viewport' content='width=device-width, initial-scale=1.0'>";
    echo "    <title>修改商品</title>";
    echo "</head>";
    echo "<body>";
    echo "    <h2>修改商品</h2>";
    echo "    <form action='/shop/modifyProduct.php' method='POST' enctype='multipart/form-data' >";
    echo "<input type='hidden' name='id' value='{$p['p_id']}' >";
    echo "        <div>";
    echo "            <label>商品名:<input type='text' name='name' value='{$p['p_name']}' ></label>";
    echo "        </div>";
    echo "        <div>";
    echo "            <label>简介: <textarea name='info' cols='30' rows='10'>{$p['p_info']}</textarea></label>";
    echo "        </div>";
    echo "        <div>";
    echo "            <label>单价:<input type='text' name='price' value='{$p['p_price']}' ></label>";
    echo "        </div>";
    echo "        <div>";
    echo "            <label>单位:<input type='text' name='unit' value='{$p['p_unit']}' ></label>";
    echo "        </div>";
    echo "        <div>";
    echo "            <label>图片:<input type='file' name='image' ></label>";
    echo "        </div>";
    echo "        <div><input type='submit' value='修改'></div>";
    echo "    </form>";
    echo "</body>";
    echo "</html>";
} else {
    echo "<h2 style='color:red;' >当前商品已被删除</h2>";
}

?>